package program

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/programs/\\d+/tasks')),
                producer('/api/programs/1/tasks'))
        headers {
            contentType(applicationJsonUtf8())
            header('id', 1)
        }
    }
    response {
        status 200
        body("""
            [{
            "title": "topic title",
              "all": [{
                "orderNumber": 1,
                "id": 1,
                "type": "必修",
                "status": "2"
              }],
              "finished": [],
              "reviewing": [],
              "unfinished": [],
              "excellent": []
            }]
        """)
        bodyMatchers {
            jsonPath('$.[*]',byType())
            jsonPath('$.[*].title',byRegex(nonEmpty()))
            jsonPath('$.[*].all.[*].id',byRegex(number()))
            jsonPath('$.[*].all.[*].title',byRegex(nonEmpty()))
            jsonPath('$.[*].all.[*].status',byRegex(nonEmpty()))
            jsonPath('$.[*].all.[*].type',byRegex(nonEmpty()))
            jsonPath('$.[*].all.[*].orderNumber',byRegex(number()))
            jsonPath('$.[*].finished',byType())
            jsonPath('$.[*].reviewing',byType())
            jsonPath('$.[*].unfinished',byType())
            jsonPath('$.[*].excellent',byType())
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }

}